<template>
  <p-table
    class="table-list-container"
    row-key="id"
    :columns="columns"
    bordered
    v-bind="$attrs"
    v-on="$listeners"
  >
    <a
      slot="serialNumber"
      slot-scope="text, record"
      @click="$emit('number-click', record)"
    >
      {{ text }}
    </a>
  </p-table>
</template>

<script>
import { PLAN_TYPE } from '@/constants/index';
import moment from 'moment';

export default {
  props: {
    planType: {
      type: String,
      default: 'BP',
    },
  },
  data() {
    return {};
  },
  computed: {
    nodeOptions() {
      return this.$store.state.dictionary.dict['plan_node'] || {};
    },
    stateOptions() {
      return this.$store.state.dictionary.dict['state'] || {};
    },
    orgOptions() {
      return this.$store.getters.getOrg({
        code: 'ltcsmsizebu',
      });
    },
    columns() {
      const columns = [
        {
          align: 'center',
          title: '序号',
          width: 60,
          customRender(t, r, index) {
            return parseInt(index) + 1;
          },
        },
        {
          align: 'center',
          title: `${PLAN_TYPE[this.planType]}编号`,
          dataIndex: 'serialNumber',
          width: 150,
          sorter: true,
          ellipsis: true,
          scopedSlots: { customRender: 'serialNumber' },
        },
        {
          align: 'center',
          title: `${PLAN_TYPE[this.planType]}名称`,
          dataIndex: 'name',
          ellipsis: true,
          width: 160,
          sorter: true,
        },
        {
          align: 'center',
          title: `${PLAN_TYPE[this.planType]}长度区间`,
          dataIndex: 'startTime',
          ellipsis: true,
          customRender: (text, row) => {
            return (
              <span>
                {moment(row.startTime).format('YYYY-MM')}
                <span> ~ </span>
                {moment(row.endTime).format('YYYY-MM')}
              </span>
            );
          },
          width: 160,
          sorter: true,
        },
        {
          align: 'center',
          title: '当前状态',
          dataIndex: 'state',
          customRender: (text) => this.stateOptions[text],
          sorter: true,
          ellipsis: true,
          width: 100,
        },
        {
          align: 'center',
          title: '当前节点',
          dataIndex: 'node',
          sorter: true,
          ellipsis: true,
          width: 120,
          customRender: (text) => this.nodeOptions[text],
        },
        {
          align: 'center',
          title: '当前处理人',
          dataIndex: 'currentUserName',
          sorter: true,
          width: 100,
          ellipsis: true,
        },
        {
          align: 'center',
          title: '销售组织',
          dataIndex: 'salesOrganization',
          sorter: true,
          ellipsis: true,
          width: 100,
          customRender: (text) => this.orgOptions[text],
        },
        {
          align: 'center',
          title: '录入截止时间',
          dataIndex: 'deadlineTime',
          width: 160,
          sorter: true,
          ellipsis: true,
        },
        {
          align: 'center',
          title: '发起人',
          dataIndex: 'createUserName',
          sorter: true,
          width: 100,
          ellipsis: true,
        },
        {
          align: 'center',
          title: '发起时间',
          dataIndex: 'createTime',
          width: 160,
          sorter: true,
          ellipsis: true,
        },
      ];
      return columns;
    },
  },

  methods: {},
};
</script>

<style lang="less" scoped>
.table-list-container {
  margin-top: 10px;
}
</style>
